package com.zhzh.sc.demo.juc.thread;

import java.util.concurrent.*;

public class ThreadPoolDemo {

    public static void main(String[] args) {
        ExecutorService executorService1 = Executors.newFixedThreadPool(10);
        ExecutorService executorService2 = Executors.newCachedThreadPool();
        ExecutorService executorService3 = Executors.newSingleThreadExecutor();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20, 0L,
                TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(10));
        for (int i = 0; i < 100; i++) {
            int finalI = i;
            executorService2.execute(new Runnable() {
                 @Override
                 public void run() {
                     try {
                         Thread.sleep(1);
                     } catch (InterruptedException e) {
                         e.printStackTrace();
                     }
                     System.out.println("name=" + Thread.currentThread().getName() + ", i=" + finalI);
                 }
             });
        }

    }
}
